package cn.rumoss.streams;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;

public class CountLongWords {

	public static void main(String[] args) throws IOException {
		
		String contents = new String(Files.readAllBytes(
				Paths.get("H:/WorkSpace/eclipseSpace/Java8Fundamental/alice30.txt")),StandardCharsets.UTF_8);
		List<String> words = Arrays.asList(contents.split("\\PL+"));
		
		long count = 0;
		for(String w : words) {
			if(w.length()>12)
				count++;
		}
		System.out.println("Count: " + count);
		
		long begin = System.currentTimeMillis();
		count = words.stream().filter(w -> w.length()>12).count();
		long end = System.currentTimeMillis();
		System.out.println("stream Count: " + count + " costs: " + (end-begin));
		
		begin = System.currentTimeMillis();
		count = words.parallelStream().filter(w -> w.length()>12).count();
		end = System.currentTimeMillis();
		System.out.println("parallelStream Count: " + count + " costs: " + (end-begin));
		
		
		
	}
	
}
